from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-26 14:13:21.566788
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 26, Sep, 2022
Time: 14:13:27
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5266
Nobs: 791.000 HQIC: -50.8540
Log likelihood: 10182.2 FPE: 6.69320e-23
AIC: -51.0584 Det(Omega_mle): 5.97764e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300722 0.053664 5.604 0.000
L1.Burgenland 0.108926 0.035765 3.046 0.002
L1.Kärnten -0.106412 0.019031 -5.591 0.000
L1.Niederösterreich 0.208388 0.074792 2.786 0.005
L1.Oberösterreich 0.102664 0.071832 1.429 0.153
L1.Salzburg 0.251677 0.038178 6.592 0.000
L1.Steiermark 0.038554 0.049921 0.772 0.440
L1.Tirol 0.106093 0.040461 2.622 0.009
L1.Vorarlberg -0.059952 0.034788 -1.723 0.085
L1.Wien 0.053628 0.064306 0.834 0.404
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062663 0.111276 0.563 0.573
L1.Burgenland -0.033311 0.074162 -0.449 0.653
L1.Kärnten 0.048142 0.039463 1.220 0.222
L1.Niederösterreich -0.172649 0.155087 -1.113 0.266
L1.Oberösterreich 0.385738 0.148949 2.590 0.010
L1.Salzburg 0.286579 0.079166 3.620 0.000
L1.Steiermark 0.107825 0.103515 1.042 0.298
L1.Tirol 0.312608 0.083900 3.726 0.000
L1.Vorarlberg 0.025836 0.072135 0.358 0.720
L1.Wien -0.016718 0.133343 -0.125 0.900
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192057 0.027557 6.969 0.000
L1.Burgenland 0.089879 0.018366 4.894 0.000
L1.Kärnten -0.008294 0.009773 -0.849 0.396
L1.Niederösterreich 0.263367 0.038407 6.857 0.000
L1.Oberösterreich 0.127478 0.036886 3.456 0.001
L1.Salzburg 0.046987 0.019605 2.397 0.017
L1.Steiermark 0.018323 0.025635 0.715 0.475
L1.Tirol 0.093660 0.020777 4.508 0.000
L1.Vorarlberg 0.058742 0.017864 3.288 0.001
L1.Wien 0.118771 0.033022 3.597 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108863 0.028226 3.857 0.000
L1.Burgenland 0.044595 0.018812 2.371 0.018
L1.Kärnten -0.015834 0.010010 -1.582 0.114
L1.Niederösterreich 0.192744 0.039339 4.900 0.000
L1.Oberösterreich 0.294384 0.037782 7.792 0.000
L1.Salzburg 0.114378 0.020081 5.696 0.000
L1.Steiermark 0.101604 0.026257 3.870 0.000
L1.Tirol 0.115312 0.021282 5.418 0.000
L1.Vorarlberg 0.071107 0.018297 3.886 0.000
L1.Wien -0.027440 0.033823 -0.811 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131901 0.051127 2.580 0.010
L1.Burgenland -0.051711 0.034075 -1.518 0.129
L1.Kärnten -0.040211 0.018132 -2.218 0.027
L1.Niederösterreich 0.171242 0.071257 2.403 0.016
L1.Oberösterreich 0.139365 0.068437 2.036 0.042
L1.Salzburg 0.285960 0.036374 7.862 0.000
L1.Steiermark 0.035925 0.047561 0.755 0.450
L1.Tirol 0.163675 0.038549 4.246 0.000
L1.Vorarlberg 0.102379 0.033143 3.089 0.002
L1.Wien 0.063661 0.061266 1.039 0.299
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059616 0.040586 1.469 0.142
L1.Burgenland 0.038470 0.027049 1.422 0.155
L1.Kärnten 0.051064 0.014393 3.548 0.000
L1.Niederösterreich 0.223127 0.056565 3.945 0.000
L1.Oberösterreich 0.283033 0.054326 5.210 0.000
L1.Salzburg 0.049325 0.028874 1.708 0.088
L1.Steiermark -0.004620 0.037755 -0.122 0.903
L1.Tirol 0.148369 0.030601 4.849 0.000
L1.Vorarlberg 0.072224 0.026310 2.745 0.006
L1.Wien 0.080320 0.048634 1.652 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181381 0.048504 3.740 0.000
L1.Burgenland -0.006072 0.032326 -0.188 0.851
L1.Kärnten -0.061088 0.017201 -3.551 0.000
L1.Niederösterreich -0.082775 0.067601 -1.224 0.221
L1.Oberösterreich 0.193109 0.064925 2.974 0.003
L1.Salzburg 0.056606 0.034507 1.640 0.101
L1.Steiermark 0.232232 0.045121 5.147 0.000
L1.Tirol 0.493484 0.036571 13.494 0.000
L1.Vorarlberg 0.048053 0.031443 1.528 0.126
L1.Wien -0.052684 0.058123 -0.906 0.365
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162198 0.055748 2.910 0.004
L1.Burgenland -0.011486 0.037154 -0.309 0.757
L1.Kärnten 0.066442 0.019770 3.361 0.001
L1.Niederösterreich 0.198544 0.077696 2.555 0.011
L1.Oberösterreich -0.059423 0.074621 -0.796 0.426
L1.Salzburg 0.214024 0.039661 5.396 0.000
L1.Steiermark 0.116088 0.051859 2.239 0.025
L1.Tirol 0.074993 0.042032 1.784 0.074
L1.Vorarlberg 0.125014 0.036138 3.459 0.001
L1.Wien 0.115766 0.066803 1.733 0.083
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360335 0.032293 11.158 0.000
L1.Burgenland 0.006636 0.021523 0.308 0.758
L1.Kärnten -0.023133 0.011452 -2.020 0.043
L1.Niederösterreich 0.220523 0.045008 4.900 0.000
L1.Oberösterreich 0.179007 0.043226 4.141 0.000
L1.Salzburg 0.045215 0.022975 1.968 0.049
L1.Steiermark -0.016385 0.030041 -0.545 0.585
L1.Tirol 0.107000 0.024348 4.395 0.000
L1.Vorarlberg 0.072727 0.020934 3.474 0.001
L1.Wien 0.049150 0.038697 1.270 0.204
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041192 0.151086 0.191102 0.155777 0.125399 0.112347 0.065484 0.223320
Kärnten 0.041192 1.000000 -0.002887 0.129155 0.041480 0.095524 0.430415 -0.053805 0.101394
Niederösterreich 0.151086 -0.002887 1.000000 0.336492 0.152201 0.300217 0.107775 0.182885 0.324584
Oberösterreich 0.191102 0.129155 0.336492 1.000000 0.231842 0.332193 0.171914 0.171057 0.263048
Salzburg 0.155777 0.041480 0.152201 0.231842 1.000000 0.146679 0.123440 0.148829 0.133472
Steiermark 0.125399 0.095524 0.300217 0.332193 0.146679 1.000000 0.153025 0.139304 0.078965
Tirol 0.112347 0.430415 0.107775 0.171914 0.123440 0.153025 1.000000 0.114040 0.152196
Vorarlberg 0.065484 -0.053805 0.182885 0.171057 0.148829 0.139304 0.114040 1.000000 0.004757
Wien 0.223320 0.101394 0.324584 0.263048 0.133472 0.078965 0.152196 0.004757 1.000000